﻿//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NetCMS.Content;
using NetCMS.Model;

public partial class manage_channel_class_list : NetCMS.Web.UI.ManagePage
{
    public manage_channel_class_list()
    {
        this.Authority_Code = "D005";
    }
    public static string ChID = string.Empty;
    Channel rd = new Channel();
    protected void Page_Load(object sender, EventArgs e)
    {
        this.CheckAdminAuthority();
        this.PageNavigator1.OnPageChange += new PageChangeHandler(PageNavigator1_PageChange);
        if (!IsPostBack)
        {
            Response.CacheControl = "no-cache";
            if (SiteID != "0")
            {
                PageError("分站没权限操作", "javascript:history.back();", true);
            }
            ChID = Request.QueryString["ChID"];
            string ParentID = Request.QueryString["ParentID"];
            if (ChID != null && ChID != string.Empty)
            {
                copyright.InnerHtml = CopyRight;
                if (Request.QueryString["Type"] != string.Empty && Request.QueryString["Type"] != null)
                {
                    string ClassID = Request.QueryString["ClassId"];
                    string oRderID = Request.QueryString["OrderId"];
                    if (ClassID != string.Empty && ClassID != null && oRderID != string.Empty && oRderID != null && NetCMS.Common.Input.IsInteger(oRderID))
                    {
                        if (int.Parse(oRderID.ToString()) > 56)
                        {
                            PageError("权重最大值为56", "javascript:history.back();", true);
                        }
                        rd.updateOrder(int.Parse(ClassID.ToString()), int.Parse(oRderID.ToString()),0);
                        PageRight("权重更新为：" + oRderID.ToString() + "成功", "javascript:history.back();", true);
                    }
                }
            }
            else
            {
                PageError("错误的参数", "javascript:history.back();", true);
            } 
            StartLoad(1);
        }
    }

    //分页处理
    protected void PageNavigator1_PageChange(object sender, int PageIndex)
    {
        StartLoad(PageIndex);
    }
    //数据初始化
    protected void StartLoad(int PageIndex)
    {
        int i, j;
        SQLConditionInfo[] st = new SQLConditionInfo[2];
        st[0] = new SQLConditionInfo("@ChID", int.Parse(ChID.ToString()));
        st[1] = new SQLConditionInfo("@ParentID", 0);
        DataTable dt = Pagination.GetPage(this.GetType().Name, PageIndex, 50, out i, out j, st);
        this.PageNavigator1.PageCount = j;
        this.PageNavigator1.PageIndex = PageIndex;
        this.PageNavigator1.RecordCount = i;
        string strchar = string.Empty;
        if (dt != null && dt.Rows.Count>0)
        {
            dt.Columns.Add("CName", typeof(string));
            dt.Columns.Add("OrderIDs", typeof(string));
            dt.Columns.Add("ST", typeof(string));
            dt.Columns.Add("OP", typeof(string));
            dt.Columns.Add("Colum", typeof(string));
            for (int k = 0; k < dt.Rows.Count; k++)
            {
                string PoPstr = string.Empty;
                dt.Rows[k]["CName"] = "<a href=\"Class_add.aspx?ClassID=" + dt.Rows[k]["ID"].ToString() + "&ChID=" + ChID + "&Action=Edit\" class=\"list_link\" title=\"点击修改,英文标志：" + dt.Rows[k]["ClassEName"].ToString() + "\">" + dt.Rows[k]["ClassCName"].ToString() + "</a>";
                dt.Rows[k]["OrderIDs"] = "<a href=\"javascript:orderAction(" + dt.Rows[k]["ID"] + "," + dt.Rows[k]["OrderID"] + ");\" class=\"list_link\" title=\"点击修改权重\"><strong>" + dt.Rows[k]["OrderID"].ToString() + "</strong></a>";
                if (dt.Rows[k]["isDelPoint"].ToString() != "0")
                {
                    PoPstr = "<span class=\"reshow\" title=\"有浏览权限\">！</span>";
                }
                if (dt.Rows[k]["islock"].ToString() == "1")
                {
                    dt.Rows[k]["ST"] = PoPstr + "&nbsp;&nbsp;<span class=\"reshow\">已锁定</span>&nbsp;&nbsp;";
                }
                else
                {
                    dt.Rows[k]["ST"] = PoPstr + "&nbsp;&nbsp;正常&nbsp;&nbsp;";
                }
                dt.Rows[k]["OP"] = "<input type=\"checkbox\" Name=\"gID\" value=\"" + dt.Rows[k]["id"].ToString() + "\">";
                int isPage = int.Parse(dt.Rows[k]["isPage"].ToString());
                if (isPage != 1)
                {
                    dt.Rows[k]["OP"] += "<a href=\"Content_add.aspx?ChID=" + Request.QueryString["ChID"] + "&ClassID=" + dt.Rows[k]["id"].ToString() + "\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/add.gif\" border=\"0\" alt=\"添加内容\"></a>";
                }
                dt.Rows[k]["OP"] += "<a href=\"class_add.aspx?ChID=" + Request.QueryString["ChID"] + "&ClassID=" + dt.Rows[k]["id"].ToString() + "&Action=Edit\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/edit.gif\" border=\"0\"></a>";
                dt.Rows[k]["OP"] += "<a href=\"preview.aspx?ChID=" + Request.QueryString["ChID"] + "&id=" + dt.Rows[k]["id"].ToString() + "&type=class\" target=\"_blank\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/review.gif\" border=\"0\"></a>";
                dt.Rows[k]["OP"] += "<a href=\"class_add.aspx?ChID=" + Request.QueryString["ChID"] + "&ClassID=" + dt.Rows[k]["id"].ToString() + "\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/addclass.gif\" border=\"0\"></a>";
                if (isPage != 1)
                {
                    dt.Rows[k]["OP"] += "<a href=\"Content.aspx?ChID=" + Request.QueryString["ChID"] + "&ClassID=" + dt.Rows[k]["id"].ToString() + "\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/review1.gif\" border=\"0\" alt=\"查看栏目下内容\"></a>";
                }
                string TmpFolder = string.Empty;
                string TmpSTR = string.Empty;
                int ClassNumber = rd.getClassNumber(int.Parse(dt.Rows[k]["id"].ToString()));
                if (ClassNumber > 0)
                {
                    TmpFolder = "<img src=\"../../sysImages/folder/yess.gif\" border=\"0\" title=\"此栏目下有" + ClassNumber + "个栏目\">";
                    TmpSTR = "<a href=\"###\" class=\"list_link\" onclick=\"ajaxGetClass('" + dt.Rows[k]["id"].ToString() + "','div_" + dt.Rows[k]["id"].ToString() + "','')\">" + TmpFolder + "</a>";
                }
                else
                {
                    TmpFolder = "<img src=\"../../sysImages/folder/nos.gif\" border=\"0\" title=\"此栏目下有0个栏目\">";
                    TmpSTR = TmpFolder;
                }
                strchar += "<div style=\"padding:3px 10px;\">(" + dt.Rows[k]["OrderIDs"] + ")&nbsp;";
                strchar += TmpSTR + "<span class=\"reshow\">(" + ClassNumber + ")</span>" + dt.Rows[k]["CName"];
                strchar += dt.Rows[k]["ST"];
                strchar += dt.Rows[k]["OP"];
                strchar += "<div style=\"width:100%;display:none;padding-left:10px;\" id=\"div_" + dt.Rows[k]["id"].ToString() + "\">loading...";
                strchar += "</div></div>";
            }
            dt.Rows[0]["Colum"] = strchar;

        }
        DataList1.DataSource = dt;
        DataList1.DataBind();
    }

    protected void Reset_allClass(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            string[] gIDARR = Str.Split(',');
            Str = null;
            int j = 0;
            int m = 0;
            for (int i = 0; i < gIDARR.Length; i++)
            {
                if (rd.Reset_allClass(int.Parse(gIDARR[i]),int.Parse(Request.QueryString["ChID"].ToString())) != 0)
                {
                    j++;
                }
                else
                {
                    m++;
                }
            }
            PageRight("成功删除" + j + "个栏目下的新闻!,失败" + m + "个(可能此栏目下没有内容)。", "class_list.aspx?ChID=" + Request.QueryString["ChID"] + "", true);
        }
    }

    protected void Lock_allClass(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            string[] gIDARR = Str.Split(',');
            Str = null;
            int j = 0;
            int m = 0;
            for (int i = 0; i < gIDARR.Length; i++)
            {
                if (rd.lockstat(int.Parse(gIDARR[i]), 1) != 0)
                {
                    j++;
                }
                else
                {
                    m++;
                }
            }
            PageRight("成功锁定" + j + "个栏目!,失败" + m + "个。", "class_list.aspx?ChID=" + Request.QueryString["ChID"] + "", true);
        }
    }

    protected void UnLock_allClass(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            string[] gIDARR = Str.Split(',');
            Str = null;
            int j = 0;
            int m = 0;
            for (int i = 0; i < gIDARR.Length; i++)
            {
                if (rd.lockstat(int.Parse(gIDARR[i]), 0) != 0)
                {
                    j++;
                }
                else
                {
                    m++;
                }
            }
            PageRight("成功解锁" + j + "个栏目!,失败" + m + "个。", "class_list.aspx?ChID=" + Request.QueryString["ChID"] + "", true);
        }
    }

    protected void Makexml(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        int ChID = int.Parse(Request.QueryString["ChID"].ToString());
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        NetCMS.Control.HProgressBar.Start();
        try
        {
            NetCMS.Control.HProgressBar.Roll("正在发布频道XML", 0);
            string[] Checkboxs = Str.Split(',');
            Str = null;
            int j = 0;
            int m = Checkboxs.Length;
            for (int i = 0; i < m; i++)
            {
                if (NetCMS.Publish.General.publishCHXML(int.Parse(Checkboxs[i].ToString()), ChID))
                {
                    j++;
                }
                NetCMS.Control.HProgressBar.Roll("共生成" + m + "个频道栏目XML，正在发布" + (i + 1) + "个。", ((i + 1) * 100 / m));
            }
            NetCMS.Control.HProgressBar.Roll("发布频道栏目XML成功,成功" + j + "个,<a class=\"list_link\" href=\"../Publish/error/geterror.aspx?\">失败" + (Checkboxs.Length - j) + "个(可能有栏目有浏览权限,或者选择的栏目下无信息)</a>.&nbsp;<a class=\"list_link\" href=\"javascript:history.back();\">返回</a>", 100);
        }
        catch (Exception ex)
        {
            NetCMS.Common.Public.savePublicLogFiles("□□□发布栏目xml,频道ID" + ChID.ToString() + "", "【错误描述：】\r\n" + ex.ToString(), UserName);
            NetCMS.Control.HProgressBar.Roll("发布频道栏目XML失败。<a  class=\"list_link\"href=\"../publish/error/geterror.aspx?\">查看日志</a>", 0);
        }
        Response.End();
    }

    protected void MakeHtml(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        int ChID = int.Parse(Request.QueryString["ChID"].ToString());
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            NetCMS.Control.HProgressBar.Start();
            NetCMS.Publish.General PG = new NetCMS.Publish.General();
            try
            {
                NetCMS.Control.HProgressBar.Roll("正在发布频道栏目", 0);
                string[] Checkboxs = Str.Split(',');
                Str = null;
                int j = 0;
                int m = Checkboxs.Length;
                for (int i = 0; i < m; i++)
                {
                    if (rd.getclassPage(int.Parse(Checkboxs[i])) == 0)
                    {
                        if (PG.publishCHSingleClass(int.Parse(Checkboxs[i].ToString()),ChID))
                        {
                            j++;
                        }
                    }
                    else
                    {
                        if (NetCMS.Publish.General.publishChPage(int.Parse(Checkboxs[i].ToString()), ChID))
                        {
                            j++;
                        }
                    }
                    NetCMS.Control.HProgressBar.Roll("共生成" + m + "个频道栏目，正在发布" + (i + 1) + "个。", ((i + 1) * 100 / m));
                }
                NetCMS.Control.HProgressBar.Roll("发布频道栏目成功,成功" + j + "个,<a class=\"list_link\" href=\"../Publish/error/geterror.aspx?\">失败" + (Checkboxs.Length - j) + "个(可能有栏目有浏览权限)</a>. &nbsp;<a class=\"list_link\" href=\"javascript:history.back();\">返回</a>", 100);
            }
            catch (Exception ex)
            {
                NetCMS.Common.Public.savePublicLogFiles("□□□发布栏目,频道ID"+ChID.ToString()+"", "【错误描述：】\r\n" + ex.ToString(), UserName);
                NetCMS.Control.HProgressBar.Roll("发布频道栏目失败。<a  class=\"list_link\"href=\"../publish/error/geterror.aspx?\">查看日志</a>", 0);
            }
            Response.End();
        }
    }

    protected void delClass(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            string[] gIDARR = Str.Split(',');
            Str = null;
            int j = 0;
            int m = 0;
            for (int i = 0; i < gIDARR.Length; i++)
            {
                if (rd.delClass(int.Parse(gIDARR[i])) != 0)
                {
                    j++;
                }
                else
                {
                    m++;
                }
            }
            PageRight("成功删除" + j + "个栏目!,失败" + m + "个栏目。", "class_list.aspx?ChID=" + Request.QueryString["ChID"] + "", true);
        }
    }
}
